﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HFController;
namespace HFWebApp.instruments
{
    public partial class InstrumentsList : BagePages
    {
        public string ClassTitle = "";
        public string sClassTitle = "";
        public string PageStr = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                this.bindOptions();

                int PageSize = 15;
                int PageNumber = 1;
                if (this.GetQuery("Page") != "")
                {
                    PageNumber = int.Parse(this.GetQuery("Page"));
                }
                int total = 0;
                string strWhere = "";
                
                #region 搜索
                if (this.GetQuery("classid") != "")
                {
                    int classid = int.Parse(this.GetQuery("classid"));
                    strWhere = "ClassID = " + classid;
                    ClassTitle = InstrumentsController.getController().getInstrumentsBigClassModel(classid).InstrumentsName;

                    Repeater2.DataSource = InstrumentsController.getController().getInstrumentsSmallClassList(classid, 9999);
                    Repeater2.DataBind();
                }
                if (this.GetQuery("sclassid") != "")
                {
                    int sclassid = int.Parse(this.GetQuery("sclassid"));
                    hf.Model.InstrumentsSmallClass sClassModel = InstrumentsController.getController().getInstrumentsSmallClassModel(sclassid);
                    hf.Model.InstrumentsBigClass bClassModel = InstrumentsController.getController().getInstrumentsBigClassModel(sClassModel.InstrumentsID);
                    strWhere = "ClassID=" + bClassModel.ID.ToString() + "and SmallClassID=" + sClassModel.ID.ToString();
                    sClassTitle = "&gt;&gt;" + sClassModel.InstrumentsName;
                    ClassTitle = bClassModel.InstrumentsName;
                    Repeater2.DataSource = InstrumentsController.getController().getInstrumentsSmallClassList(bClassModel.ID, 9999);
                    Repeater2.DataBind();
                }
                #endregion

                Repeater1.DataSource = InstrumentsController.getController().getInstrumentsList(PageSize, PageNumber, strWhere, out total);
                Repeater1.DataBind();
                PageStr = LLL.Pager.TrunPageHtmlCode_Web(PageSize, PageNumber, total, "");
            }
        }

        private void bindOptions()
        {
            iBigClassOption.DataSource = InstrumentsController.getController().getInstrumentsBigClassList(99999);
            iBigClassOption.DataBind();
        }

        public int GetCount(string SmallClassID)
        {
            return InstrumentsController.getController().getInstrumentsContent("SmallClassID=" + SmallClassID.ToString());
        }
    }
}